package com.itheima.concurrent;

public class WaitTest {

    /**
     * 两个线程交替打印 1-100
     */
    public static void main(String[] args) {
        Dayin dayin = new Dayin();
        Thread t1 = new Thread(dayin);
        t1.setName("线程1");
        Thread t2 = new Thread(dayin);
        t2.setName("线程2");
        t1.start();
        t2.start();
    }

    }
class Dayin implements Runnable {

    int num = 1;

    @Override
    public void run() {
        while (num <= 100) {
            synchronized (this) {
                notify();
                System.out.println(Thread.currentThread().getName() + "====> " + num);
                num ++;
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
